﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using System.Data.OleDb;

public partial class search : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.Form["Submit"] != null)
        {
            OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\air\Desktop\ASP.net\App_Data\MainDB.mdb;Persist Security Info=True");
            string str = "SELECT * FROM [Species] WHERE";
            if (Request.Form["ScientificName"] != "") str += " ScientificName   LIKE '%" + Request.Form["ScientificName"] + "%' AND";
            if (Request.Form["ChineseName"] != "") str += " ChineseName LIKE '%" + Request.Form["ChineseName"] + "%' AND";
            if (Request.Form["CommonName"] != "") str += " CommonName LIKE '%" + Request.Form["CommonName"] + "%' AND";
            if (Request.Form["FlowerColor"] != null) str += " FlowerColor=" + Request.Form["FlowerColor"] + " AND";
            if (Request.Form["FlowerStyle"] != null) str += " FlowerStyle=" + Request.Form["FlowerStyle"] + " AND";
            if (Request.Form["FlowerSize"] != null) str += " FlowerSize=" + Request.Form["FlowerSize"] + " AND";
            if (Request.Form["LeafStyle"] != null) str += " LeafStyle=" + Request.Form["LeafStyle"] + " AND";
            if (Request.Form["Height"] != null) str += " Height=" + Request.Form["Height"] + " AND";
            if (Request.Form["PopIntro"] != "") str += " PopIntro LIKE '%" + Request.Form["PopIntro"] + "%' AND";
            str = str.TrimEnd(new char[] { ' ', 'A', 'N', 'D' });
            Response.Write(str + "<br />");
            OleDbCommand mycomm = new OleDbCommand(str, conn);
            conn.Open();
            OleDbDataReader rs = mycomm.ExecuteReader();
            while (rs.Read())
                Response.Write("<a href=\"show.aspx?ID=" + rs[0] + "\">" + rs[2] + "</a><br />");
            conn.Close();
        }
    }
}
